#include "stdafx.h"
#include "FrameManager.h"

CFrameManager::CFrameManager(void)
{
    m_arraySpriteManagers.SetSize(MAX_FRAMES);
    m_uiOffset = 0;
}

CFrameManager::~CFrameManager(void)
{
}

void CFrameManager::CreateFrame(CSpriteManager& spriteManager)
{
    m_critialSection.Lock(INFINITE);
    m_arraySpriteManagers.SetAt(m_uiOffset, spriteManager);
    m_uiOffset++;
    if (m_uiOffset == MAX_FRAMES)
    {
        m_uiOffset = 0;
    }
    m_critialSection.Unlock();
}

CSpriteManager& CFrameManager::GetFrame(UINT uiOffset)
{    
    m_critialSection.Lock(INFINITE);
    CSpriteManager& scriptManager = m_arraySpriteManagers.GetAt(uiOffset);
    m_critialSection.Unlock();

    return scriptManager;
}

UINT CFrameManager::GetOffset()
{
    UINT uiOffset;

    m_critialSection.Lock(INFINITE);
    uiOffset = m_uiOffset;
    m_critialSection.Unlock();

    return uiOffset;
}
